package com.itany.mall.service.impl;

import java.util.List;

import com.itany.mall.dao.ProductTypeDao;
import com.itany.mall.entity.ProductType;
import com.itany.mall.exception.ProductTypeNameExistsException;
import com.itany.mall.factory.Autowired;
import com.itany.mall.factory.Component;
import com.itany.mall.service.ProductTypeService;

@Component("productTypeServiceImpl")
public class ProductTypeServiceImpl implements ProductTypeService {

	@Autowired
	private ProductTypeDao productTypeDao;

	@Override
	public List<ProductType> findAll() {
		return productTypeDao.selectAll();
	}

	@Override
	public void addProductType(String name) throws ProductTypeNameExistsException {
		// select by name 判断查询结果是否为null
		ProductType check = productTypeDao.selectByName(name);
		if (check != null) {
			throw new ProductTypeNameExistsException();
		}
		ProductType t = new ProductType().setName(name);
		productTypeDao.insert(t);
	}

}
